import pandas as pd
pd.set_option('display.unicode.east_asian_width',True)
df = pd.DataFrame({
    '班级':['一班','一班','一班','二班','二班','二班'],
    '姓名':['5','6','7','8','9','10'],
    '语文':['85','102','96','125','130','115'],
    '数学':['66','77','88','99','100','110'],
    '英语':['55','56','57','58','59','50']
})
print('原始数据：\n',df)
group1=df.groupby('班级')
print('以班级列按行分组：')
for i in group1:
    print(i)

print('分组后一班的数据：\n',group1.get_group('一班'))
print('每个班每个科目的平均成绩：\n',group1.agg('mean',numer))
group2=df.groupby({'语文':'总成绩','数学':'总成绩','英语':'总成绩'},axis=1)
print('以列标签按列分组')
for i in group2:
    print(i)

print('添加总成绩之后的数据：\n',df)